package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;

@Data
@ToString
public class OrderConfirmVo {

    /**
        收货地址，ums_member_receive_address表
     */
    List<MemberAddressVo> address;

    /**
        所有选中的购物项
     */
    List<OrderItemVo> items;

    /**
        优惠券信息
     */
    Integer integration;

    /*
        防重令牌
     */
    String orderToken;

    public Integer getCount() {
        Integer i = 0;
        if (items!=null) {
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items!=null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }
}
